package client.comm.baoding.widget;

import android.content.Context;
import android.view.Gravity;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import client.comm.baoding.R;
import client.comm.baoding.adapter.BankTypeAdapter;
import razerdp.basepopup.BasePopupWindow;

public class BankTypePop extends BasePopupWindow {

    private OnItemClickListener mOnItemClickListener;
    private List<String> mTypeData;

    public BankTypePop(Context context, List<String> data) {
        super(context);
        setPopupGravity(Gravity.BOTTOM);
        mTypeData = data;
        initView();
    }

    @Override
    public View onCreateContentView() {
        return createPopupById(R.layout.item_pop_bank);
    }

    private void initView() {
        findViewById(R.id.iv_close).setOnClickListener(v -> dismiss());

        RecyclerView rvList = findViewById(R.id.rv_list);
        rvList.setLayoutManager(new LinearLayoutManager(getContext()));
        BankTypeAdapter itemAdapter = new BankTypeAdapter(mTypeData);
        rvList.setAdapter(itemAdapter);
        itemAdapter.setOnItemClickListener((adapter, view, position) -> {
            if (mOnItemClickListener != null) {
                itemAdapter.setCurrentIndex(position);
                mOnItemClickListener.onClick(itemAdapter.getItem(position));
                dismiss();
            }
        });

    }

    public OnItemClickListener getOnItemClickListener() {
        return mOnItemClickListener;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onClick(String bean);
    }
}
